//
//  TalksInfoHeaderView.m
//  Liuhe
//
//  Created by zr on 2018/8/14.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "TalksInfoHeaderView.h"


@interface TalksInfoHeaderView ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * popularLabel;
@property (nonatomic, weak)UIImageView * contentImageView;
@property (nonatomic, weak)UITextView * textView;
@property (nonatomic, weak)UIView * lineView;

@end


@implementation TalksInfoHeaderView


- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
//    NSLog(@"dict===%@",dict);
    self.titleLabel.text = [NSString stringWithFormat:@"#%@#",dict[@"title"]];
    self.popularLabel.text = [NSString stringWithFormat:@"阅读 %@",dict[@"read"]];
    
    NSArray * arr = dict[@"images"];
    NSURL * url = [NSURL URLWithString:arr.firstObject];
    
    [self.contentImageView sd_setImageWithURL:url];
    
    self.textView.text = dict[@"content"];
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = MAINCOLOR;
    titleLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    titleLabel.text = @"#你妈催你结婚了吗？#";
    
    self.titleLabel = titleLabel;
    
    [self addSubview:self.titleLabel];
    
    
    UILabel * popularLabel = [UILabel new];
    
    popularLabel.textColor = ColorWithRGB(0xB3B3B3);
    popularLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    popularLabel.text = @"人气9406  参与42";
    
    self.popularLabel = popularLabel;
    
    [self addSubview:self.popularLabel];
    
    
    UIImageView * contentImageView = [UIImageView new];
    
    contentImageView.backgroundColor = [UIColor yellowColor];
    
    self.contentImageView = contentImageView;
    
    [self addSubview:self.contentImageView];
    
    
    UITextView *textView =[[UITextView alloc] init];
    textView.backgroundColor= [UIColor whiteColor];
    textView.text = @"昂上大V哪怕是大V哪怕是地方那是的发市那地方女爬到SVN阿萨德女爱豆你发市案频繁市爬上巅峰v 奥斯陆俊了丢；大V你哈皮；奥德赛女爱豆深V狗爬式东方市河南省大V那山洞i";
    textView.textColor = [UIColor blackColor];
    textView.editable = NO;
    textView.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.textView = textView;
    
    [self addSubview:self.textView];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self).offset(10 * SCREENH6);
    }];
    
    [self.popularLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.popularLabel);
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
        make.height.mas_equalTo(150 * SCREENH6);
        make.top.mas_equalTo(self.popularLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentImageView);
        make.height.mas_equalTo(70 * SCREENH6);
        make.top.mas_equalTo(self.contentImageView.mas_bottom).offset(14 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self);
        make.height.mas_equalTo(2 * SCREENH6);
        make.bottom.mas_equalTo(self);
    }];
}

@end
